<template>
  <el-dialog :append-to-body="true" :visible.sync="dialog" :title="配置" width="600px">
    <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="80px">
      <el-form-item label="定位设备">
        <el-select v-model="form.workerDevicesArray" style="width:450px" multiple filterable placeholder="请选择">
          <el-option
            v-for="(item, index) in dict.workerDeviceDict"
            :key="item.workerDeviceNum"
            :label="item.workerDeviceNum"
            :value="item.workerDeviceNum">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doEdit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { add, edit,config } from '@/api/peopleDevice'
export default {
  props: {
    isAdd: {
      type: Boolean,
      required: true
    },
    sup_this: {
      type: Object,
      default: null
    },
    dict: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      loading: false, dialog: false,
      form: {
        id: '',
        workerDevices: '',
        deviceName: '',
        deviceIp: '',
        devicePort: '',
        devicePoint: '',
        deviceArea: '',
        refreshRate: '',
        deviceNum: '',
        deviceType: '',
        deviceModel: '',
        deviceGrade: '',
        deviceBrand: '',
        manufacturer: '',
        creator: '',
        createTime: '',
        updator: '',
        updateTime: ''
      }, rules: {

      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doEdit() {
      const workerDevicesArray = this.form.workerDevicesArray;
      this.form.workerDevices = workerDevicesArray.join(",");
      config(this.form).then(res => {
        this.resetForm()
        this.$notify({
          title: '修改成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.sup_this.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
      this.form = {
        id: '',
        workerDevices: '',
        deviceName: '',
        deviceIp: '',
        devicePort: '',
        devicePoint: '',
        deviceArea: '',
        refreshRate: '',
        deviceNum: '',
        deviceType: '',
        deviceModel: '',
        deviceGrade: '',
        deviceBrand: '',
        manufacturer: '',
        creator: '',
        createTime: '',
        updator: '',
        updateTime: ''
      }
    }
  }
}
</script>

<style scoped>
  .form_input {
    width: 180px;
  }

  .form_input_row {
    width: 455px;
  }
</style>
